import Vue from 'vue'
import Vuet from 'vuet'
import * as request from '../request'
import * as storage from '../storage'

Vue.use(Vuet)
let avatar = require('../assets/images/avatar.png')

export default new Vuet({
  pathJoin: '-',
  modules: {
    // 商品分类列表
    goodsClassList: {
      data () {
        return []
      },
      async fetch ({state, route, params, path}) {
        const data = await request.getGoodsClassList()
        return data
      }
    },
    // 收货地址列表
    addressList: {
      data () {
        return {requested: false, loading: true, data: []}
      },
      async fetch() {
        const response = await request.getAddressList()
        return {requested: true, loading: false, data: response.data}
      }
    },
    // 银行卡列表
    bankcardList: {
      data () {
        return {requested: false, loading: true, data: []}
      },
      async fetch() {
        const response = await request.getBankcardList()
        return {requested: true, loading: false, data: response}
      }
    },
    // 商店地址列表
    shopAddressList: {
      data () {
        return {requested: false, loading: true, data: []}
      },
      async fetch() {
        const response = await request.getShopAddressList()
        return {requested: true, loading: false, data: response}
      }
    },
    // 临时保存的购物车选中的商品id列表，用于请求生成订单（购物车->订单确认 之间的数据传递）
    // selectedCartIdList: {
    //   data () {
    //     return []
    //   },
    //   async fetch() {
    //     return []
    //   }
    // },
    // 用户信息
    memberInfo: {
      data () {
        return storage.getMemberInfo() || {member_mobile: '', balance: 0, integral: 0, member_avatar: avatar, qrcode_image: '', member_name: '', member_truename: '', member_id: '', is_brush_man: '', freeze_balance: '', a_rate: 0, b_rate: 0, c_rate: 0, w_rate: 0}
      },
      async fetch() {
        try {
          const data = await request.getMemberInfo()
          if (!data.member_avatar || data.member_avatar == '') {
            data.member_avatar = avatar
          }
          storage.setMemberInfo(data)
          return data
        } catch (e) {
        }
      }
    },
    // 退款原因列表
    refundMoneyReasonList: {
      data () {
        return []
      },
      async fetch() {
        const data = await request.getRefundReasonList('0')
        return data
      }
    },
    // 退货原因列表
    refundGoodsReasonList: {
      data () {
        return []
      },
      async fetch() {
        const data = await request.getRefundReasonList('1')
        return data
      }
    },
    // 物流列表
    expressList: {
      data () {
        return []
      },
      async fetch() {
        const data = await request.getExpressList()
        return data
      }
    },
    // 银行卡类型列表
    bankList: {
      data () {
        return []
      },
      async fetch() {
        const data = await request.getBankList()
        return data
      }
    },
    // 绑定的银行卡
    bankCard: {
      data () {
        return {account_name: '', add_time: '', bank_id: '', is_default: '', mb_id: '', member_bank_num: '', member_id: '', member_mobile: ''}
      },
      async fetch() {
        const data = await request.getBankcard()
        return data
      }
    },
    // app微信登录的微信信息
    wxInfo: {
      data () {
        return {}
      }
    },
    walletInfo: {
      data () {
        return {state: '', balance: '', rate: 0}
      },
      async fetch() {
        const data = await request.getWalletInfo()
        return data
      }
    },
    isApp: {
      data () {
        return {requested: false, data: false}
      }
    }
  }
})
